keil5中多文件引用外部变量时候的static和extern

您所在的位置:网站首页 static 多文件 keil5中多文件引用外部变量时候的static和extern

keil5中多文件引用外部变量时候的static和extern

2024-07-09 23:58| 来源: 网络整理| 查看: 265

//数据定义 extern static u16 AD_Vtemp[10];//装载10次ADC采样数据 extern static u16 AD_val; //ADC单次采样数据

出现了这样的错误 MAIN.C(8): error C141: syntax error near ‘static’ MAIN.C(9): error C141: syntax error near ‘static’

下面是C语言标准: If, within a translation unit, the same identifier appears with both internal and external linkage, the behavior is undefined. 而引用 For an identifier declared with the storage-class specifier extern in a scope in which a prior declaration of that identifier is visible, if the prior declaration specifies internal or external linkage, the linkage of the identifier at the later declaration is the same as the linkage specified at the prior declaration. If no prior declaration is visible, or if the prior declaration specifies no linkage, then the identifier has external linkage. 所以先出现 extern 后出现 static 是不行的,用extern外部声明即可

//数据定义 extern u16 AD_Vtemp[10];//装载10次ADC采样数据 extern u16 AD_val; //ADC单次采样数据

改成如上后,编译通过



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3